
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html >
<html >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="./Style/skin.css" />
    <script src=" Js/jquery-3.3.1.min.js"></script>
    <script>
        function getCurrentDate(){
            var dateObj = new Date();
            var year = dateObj.getFullYear();
            var month = dateObj.getMonth()+1;//0~ 11
            var date = dateObj.getDate();
            var dateStr = year+"-"+(month>=10?month:"0"+month)+"-"+(date>=10?date:"0"+date);
            return dateStr;
        }
        function getBackDate(count){
            //1.获取系统的当前时间
            var dateObj = new Date();
            //2.转成毫秒数
            var mills = dateObj.getMilliseconds();
            //3
            mills += count*24*60*60*1000;
            //4.转成日期出来
            dateObj.setMilliseconds(mills);
            //5.时间转成字符串
            var year = dateObj.getFullYear();
            var month = dateObj.getMonth()+1;//0~ 11
            var date = dateObj.getDate();
            var dateStr = year+"-"+(month>=10?month:"0"+month)+"-"+(date>=10?date:"0"+date);
            return dateStr;
        }
        $(function () {

            $("#btnQueryBook").prop("disabled","disabled");
            $("#btnSubmit").prop("disabled","disabled");
            var member =null;
            $("#btnQuery").click(function () {
            //1.获取用户的编号
            var content =$("#memberId").val();
            if(!content){
                //是否为空;
                alert("请输入用户id")
                return;
            }
            var url="member.let?type=doajax&id="+content;
            //2.调用ajax

                $.get(url,function (data,status) {
                    console.log(data);
                    //{"balance":200.0,"id":2,"idNumber":"430311199909120054","name":"ada","pwd":"ada123","regdate":1635177600000,"tel":"13678096545"}
                    //json字符串转换成json对象
                     member =JSON.parse(data);
                    console.log(member.balance+""+member.amount+""+member.name);
                    //2.给组件赋值
                    $("#name").val(member.name);
                    $("#amount").val(member.amount);
                    $("#balance").val(member.balance);

                });
                $(this).prop("disabled","disabled");
                $("#btnQueryBook").removeAttr("disabled");
               // $("#btnQueryBook").removeattr("disabled");
            });
            $("#btnQueryBook").click(function () {
            var name =$("#bookContent").val();//获取值;
            var url ="book.let?type=doajax&name="+name;
            $.get(url,function (data,status) {
              console.log(data);
              if(data==="{}") {
                  alert("当前书不存在!");
                  $("#bookContent").val("");
                  return;
              }
              var book =JSON.parse(data);
                  var tr = $("<tr align=\"center\" class=\"d\">");
                  //2.创建多个列
                  var tdCheck = $("<td><input type=\"checkbox\" value=\""+book.id+"\" class=\"ck\" checked /></td>");
                  var tdName = $("<td>"+book.name+"</td>");
                  //借阅日期：系统当前时间
                  //归还日期：系统当前时间 +会员等级中.keeyDay
                  var tdRentDate = $("<td>"+getCurrentDate()+"</td>");
                  var tdBackDate = $("<td>"+getBackDate(30)+"</td>");
                  var tdPublish = $("<td>"+book.publish+"</td>");
                  var tdAddress = $("<td>"+book.address+"</td>");
                  var tdPrice = $("<td>"+book.price+"</td>");
                  //3.行加列
                  tr.append(tdCheck);
                  tr.append(tdName);
                  tr.append(tdRentDate);
                  tr.append(tdBackDate);
                  tr.append(tdPublish);
                  tr.append(tdAddress);
                  tr.append(tdPrice);
                  //4.表加行
                  $("#tdBook").append(tr);
                 $("#bookContent").val("");//清空书籍;
                  $("#btnSubmit").removeAttr("disabled");
                    $("#btnSubmit").click(function () {
                    var ids = new Array();
                    var count=0;
                    $(".ck").each(function () {
                    if($(this).prop("checked")){
                        ids.push($(this).val())
                        count++;
                    }

                    });
                    if(count===0){
                        alert("请选择借阅书籍");
                        return;
                    }
                     if(count>member.amount){
                        alert("借阅数量超出可借数量");
                        return;
                    }
                     location.href="record.let?type=add&mid="+member.id+"&ids="+ids.join("_");

                    });

            });
            });

        });
    </script>
</head>
    <body>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <!-- 头部开始 -->
            <tr>
            
                <td colspan="3"  valign="top" background="./Images/context.png">
                    <img src="Images/context.png" >
                </td>
                <td ></td>
            </tr>
            <!-- 中间部分开始 -->
            <tr>
                <!--第一行左边框-->
            
                <!--第一行中间内容-->
                <td valign="top" bgcolor="#ffffff">
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                        <!-- 空白行-->
                        <tr><td colspan="2" valign="top">&nbsp;</td><td>&nbsp;</td><td valign="top">&nbsp;</td></tr>
                        <tr>
                            <td colspan="4">
                                <table>
                                    <tr>
                                        <td width="100" align="center"></td>
                                        <td valign="bottom"><h3 style="letter-spacing:1px;">常用功能 > 图书借阅 </h3></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <!-- 一条线 -->
                        <tr>
                            <td height="20" colspan="4">
                                <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
                                    <tr><td></td></tr>
                                </table>
                            </td>
                        </tr>
                        <!-- 会员信息开始 -->
                        <tr>
                            <td width="2%">&nbsp;</td>
                            <td width="96%">
                                <fieldset>
                                    <legend>查询会员</legend>
                                    <table width="100%" border="1" class="cont"  >
                                        <tr>
                                            <td width="8%" class="run-right"> 会员编号</td>
                                            <td colspan="7"><input class="text" type="text" id="memberId" name="memberId"/> 
                                                 <input type="button" id="btnQuery" value="确定" style="width: 80px;"/></td>
                           
                                            </td>
                                         
                                        </tr>
                                        <tr>
                                            <td width="8%" class="run-right">会员名称</td>
                                            <td width="17%"><input class="text" type="text" id="name"  disabled/></td>
                                            <td width="8%" class="run-right">可借数量</td>
                                            <td width="17%"><input class="text" type="text" id="amount"  disabled/></td>
                                            <td width="8%" class="run-right">账户余额</td>
                                            <td width="17%"><input class="text" type="text" id="balance" disabled/></td>
                                        </tr>
                                    </table>
                                </fieldset>
                            </td>
                            <td width="2%">&nbsp;</td>
                        </tr>
                      
                        <!--空行-->
                        <tr>
                            <td height="40" colspan="3">
                            </td>
                        </tr>
                        
                        <!--图书搜索条-->
                        <tr>
                            <td width="2%">&nbsp;</td>
                            <td width="96%">
                                <fieldset>
                                    <legend>查询图书</legend>
                                    <table width="100%" border="1" class="cont"  >
                                        <tr>
                                            <td colspan="8">
                                                请输入:&nbsp;&nbsp;<input class="text" type="text" id="bookContent" name="bookContent" placeholder="输入书名"/>
                                                <input type="button" id="btnQueryBook" value="确定" style="width: 80px;"/>
                                                <input type="button" id="btnSubmit" value="完成借阅" style="width: 80px;"/>
                                            </td>
                                         
                                        </tr>
                                       
                                    </table>
                                </fieldset>
                            </td>
                            <td width="2%">&nbsp;</td>
                        </tr>
                        <tr><td height="20" colspan="3"></td></tr>
                        <tr>
                            <td width="2%">&nbsp;</td>
                            <td width="96%">
                                <table width="100%">
                                    <tr>
                                        <td colspan="2">
                                            <form action="" method="">
                                                <table width="100%"  class="cont tr_color" id ="tdBook">
                                                    <tr>
                                                        <th><input id="ckAll" type="checkbox" value=""/>全选/全不选</th>
                                                        <th>书籍名</th>
                                                        <th>借阅时间</th>
                                                        <th>应还时间</th>
                                                        <th>出版社</th>
                                                        <th>书架</th>
                                                        <th>定价(元)</th>
                                                    </tr>


                                                </table>
                                            </form>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="2%">&nbsp;</td>
                        </tr>
                        <!-- 产品列表结束 -->
                        <tr>
                            <td height="40" colspan="4">
                                <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
                                    <tr><td></td></tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td width="2%">&nbsp;</td>
                            <td width="51%" class="left_txt">
                               
                            </td>
                            <td>&nbsp;</td><td>&nbsp;</td>
                        </tr>
                    </table>
                </td>
                
            </tr>
            <!-- 底部部分 -->
            <tr>
                <td colspan="3"  valign="top" background="Images/U3%25~J%7B$@OG%5D%60(1UF%7DW)UIGO.png">
                    <img src="Images/U3%25~J%7B$@OG%5D%60(1UF%7DW)UIGO.png" >
                </td>
            </tr>
        </table>
    </body>
</html>